<?php
// +----------------------------------------------------------------------
// | 员工可服务项目列表
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
use think\Validate;

class ShopStaffService extends Model
{
	
	// ----------------
	// ---模型事件---
	//----------------
	protected static function init()
	{
    	//插入前验证
    	self::event('before_insert', function ($param) {
	    	$validate = new Validate;
			$validate->rule([
				'staff_id|员工id'=>'require|integer',
				'goods_id|商品id'=>'require|integer'
			]);
	        if(!$validate->check($param)){
	        	throw new \think\Exception($validate->getError());
	        }
        });
    }
	
	//项目，一对一关联
	public function project(){
        return $this->hasOne('goods','id','proj_id')->bind([
        	'proj_name'=>'name'
        ]);
    }	
}
